package vista;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controlador.interfaces.IControladorUsuario;
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;

import vista.interfaces.IVistaUsuario;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VistaUsuario extends JFrame implements IVistaUsuario {
	private JPanel jPanel1;
	private JTextField txtNombre;
	private JButton btnGuardar;
	private JTextField txtRut;
	private JLabel lblRut;
	private JLabel lblNombre;
	private IControladorUsuario controladorUsuario;

	
	public VistaUsuario() throws HeadlessException {
		super();
		initGUI();
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosing(WindowEvent arg0) {
				controladorUsuario.close();
			}
			
			@Override
			public void windowClosed(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowActivated(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	public void mostrar() {
		this.setVisible(true);
	}
	
	@Override
	public String getNombre() {
		return txtNombre.getText();
	}

	@Override
	public String getRut() {	
		return txtRut.getText();
	}

	@Override
	public void setNombre(String nombre) {
		this.txtNombre.setText(nombre);
	}

	@Override
	public void setRut(String rut) {
		this.txtRut.setText(rut);
	}

	@Override
	public void setControlador(IControladorUsuario controladorUsuario) {
		this.controladorUsuario = controladorUsuario;
	}
	
	private void initGUI() {
		try {
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				{
					lblNombre = new JLabel();
					jPanel1.add(lblNombre);
					lblNombre.setText("Nombre:");
					lblNombre.setBounds(52, 44, 71, 17);
				}
				{
					lblRut = new JLabel();
					jPanel1.add(lblRut);
					lblRut.setText("Rut:");
					lblRut.setBounds(52, 80, 71, 17);
				}
				{
					txtNombre = new JTextField();
					jPanel1.add(txtNombre);
					txtNombre.setBounds(128, 41, 151, 24);
				}
				{
					txtRut = new JTextField();
					jPanel1.add(txtRut);
					txtRut.setBounds(128, 77, 151, 24);
				}
				{
					btnGuardar = new JButton();
					jPanel1.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(128, 122, 83, 24);
					btnGuardar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnGuardarActionPerformed(evt);
						}
					});
				}
			}
			{
				this.setSize(333, 184);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void btnGuardarActionPerformed(ActionEvent evt) {
		this.controladorUsuario.guardar();
	}

}
